﻿<UserControl x:Class="TitlebarButtons"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:shell="http://schemas.microsoft.com/winfx/2006/xaml/presentation/shell"
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             mc:Ignorable="d"
             d:DesignHeight="32" d:DesignWidth="144"
             shell:WindowChrome.IsHitTestVisibleInChrome="True">
    <UserControl.Resources>
        <Style TargetType="{x:Type Path}">
            <Setter Property="VerticalAlignment" Value="Center" />
            <Setter Property="HorizontalAlignment" Value="Center" />
            <Setter Property="Fill" Value="#C0000000" />
        </Style>
        <Style TargetType="{x:Type Button}">
            <Setter Property="Focusable" Value="False" />
            <Setter Property="IsTabStop" Value="False" />
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type Button}">
                        <Grid x:Name="g">
                            <Rectangle x:Name="bg" Fill="#20000000" Opacity="0" />
                            <ContentPresenter />
                        </Grid>
                        <ControlTemplate.Triggers>
                            <Trigger Property="IsMouseOver" Value="True">
                                <Setter TargetName="bg" Property="Opacity" Value="1" />
                                <Trigger.EnterActions>
                                    <StopStoryboard BeginStoryboardName="mouseleave" />
                                </Trigger.EnterActions>
                                <Trigger.ExitActions>
                                    <BeginStoryboard x:Name="mouseleave">
                                        <Storyboard DecelerationRatio="1" FillBehavior="Stop">
                                            <DoubleAnimation From="1" To="0" Duration="0:0:0.3" 
                                                             Storyboard.TargetName="bg"
                                                             Storyboard.TargetProperty="Opacity" />
                                        </Storyboard>
                                    </BeginStoryboard>
                                </Trigger.ExitActions>
                            </Trigger>
                            <Trigger Property="IsPressed" Value="True">
                                <Setter TargetName="bg" Property="Fill" Value="#10000000" />
                            </Trigger>
                            <Trigger Property="IsEnabled" Value="False">
                                <Setter TargetName="g" Property="Visibility" Value="Hidden" />
                            </Trigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
    </UserControl.Resources>
    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition />
            <ColumnDefinition />
            <ColumnDefinition />
        </Grid.ColumnDefinitions>
        <Button Grid.Column="0" x:Name="b_min" Command="{x:Static shell:SystemCommands.MinimizeWindowCommand}">
            <Path Data="M0,7 H10 V10 H0 z" />
        </Button>
        <Button Grid.Column="1" x:Name="b_max" Command="{x:Static shell:SystemCommands.MaximizeWindowCommand}">
            <Path Data="M0,0 H10 V10 H0 z M1,3 H9 V9 H1 z" />
        </Button>
        <Button Grid.Column="1" x:Name="b_res" Command="{x:Static shell:SystemCommands.RestoreWindowCommand}">
            <Path Data="M3,0 H12 V8 H9 V12 H0 V4 H3 z M4,2 H11 V7 H9 V4 H4 z M1,6 H8 V11 H1 z" />
        </Button>
        <Button Grid.Column="2" x:Name="b_cls" Command="{x:Static shell:SystemCommands.CloseWindowCommand}">
            <Path Data="M0,1 H3 L6,4 L9,1 H12 L7.5,5.5 L12,10 H9 L6,7 L3,10 H0 L4.5,5.5 z" />
        </Button>
    </Grid>
</UserControl>
